package demo01;

import java.util.List;
import java.util.Random;

class MyThread5 extends Thread {
	private final List<Integer> prizes;
	private final Box box1;
	private final Box box2;
	private final Random random = new Random();
	private int count = 0;

	public MyThread5(List<Integer> prizes, Box box1, Box box2, String name) {
		super(name);
		this.prizes = prizes;
		this.box1 = box1;
		this.box2 = box2;
	}

	public int getCount() {
		return count;
	}

	@Override
	public void run() {
		while (true) {	
			Integer prize;
			synchronized (prizes) {
				if (prizes.isEmpty()) {
					break;
				}
				int index = random.nextInt(prizes.size());
				prize = prizes.remove(index);
				count++;
			}
			try {
				Thread.sleep(100); 
			} catch (InterruptedException e) {
				e.printStackTrace();
				break;
			}
		}
	}
}